
<?php

function checkQualified($required) {
	$req_piece = preg_split('//', $required,-1,PREG_SPLIT_NO_EMPTY);
	$cur_piece = preg_split('//', $_SESSION[permission],-1,PREG_SPLIT_NO_EMPTY);
/*
print "<!-- ";
	print_r($req_piece);
	print_r($cur_piece);
print " --> ";
*/
	if($required >= 1000) {
		//check for ams and admins here
		if(($req_piece[0] == 1) and (($cur_piece[0] == 1) or ($cur_piece[0] == 3) or ($cur_piece[0] == 5) or ($cur_piece[0] == 7))) {
			return true;
		} else if(($req_piece[0] == 2) and (($cur_piece[0] == 2) or ($cur_piece[0] == 3) or ($cur_piece[0] == 6) or ($cur_piece[0] == 7))) {
			return true;
		} else if(($req_piece[0] == 4) and (($cur_piece[0] == 4) or ($cur_piece[0] == 5) or ($cur_piece[0] == 6) or ($cur_piece[0] == 7))) {
			return true;
		} else {
			return false;
		}		
	} else if ($required >= 100) {
		//check for dispatch, pm and training
		if(($req_piece[1] == 1) and (($cur_piece[1] == 1) or ($cur_piece[1] == 3) or ($cur_piece[1] == 5) or ($cur_piece[1] == 7))) {
			return true;
		} else if(($req_piece[1] == 2) and (($cur_piece[1] == 2) or ($cur_piece[1] == 3) or ($cur_piece[1] == 6) or ($cur_piece[1] == 7))) {
			return true;
		} else if(($req_piece[1] == 4) and (($cur_piece[1] == 4) or ($cur_piece[1] == 5) or ($cur_piece[1] == 6) or ($cur_piece[1] == 7))) {
			return true;
		} else {
			return false;
		}		
	} else if ($required >= 10) {
		//check for buckland and storrs/mansfield
		if(($req_piece[2] == 1) and (($cur_piece[2] == 1) or ($cur_piece[2] == 3) or ($cur_piece[2] == 5) or ($cur_piece[2] == 7))) {
			return true;
		} else if(($req_piece[2] == 2) and (($cur_piece[2] == 2) or ($cur_piece[2] == 3) or ($cur_piece[2] == 6) or ($cur_piece[2] == 7))) {
			return true;
		} else if(($req_piece[2] == 4) and (($cur_piece[2] == 4) or ($cur_piece[2] == 5) or ($cur_piece[2] == 6) or ($cur_piece[2] == 7))) {
			return true;
		} else {
			return false;
		}		
	} else if ($required >= 1) {
		//check for trainee, buswash and shuttle
		if(($req_piece[3] == 1) and (($cur_piece[3] == 1) or ($cur_piece[3] == 3) or ($cur_piece[3] == 5) or ($cur_piece[3] == 7))) {
			return true;
		} else if(($req_piece[3] == 2) and (($cur_piece[3] == 2) or ($cur_piece[3] == 3) or ($cur_piece[3] == 6) or ($cur_piece[3] == 7))) {
			return true;
		} else if(($req_piece[3] == 4) and (($cur_piece[3] == 4) or ($cur_piece[3] == 5) or ($cur_piece[3] == 6) or ($cur_piece[3] == 7))) {
			return true;
		} else {
			return false;
		}
	} else {
		//check if the person is eligible to sign up
		if($cur_piece[3] > 0) {
			return true;
		} else {
			return false;
		}
	}
}

?>
